%%%-------------------------------------------------------------------
%%% File    : gtable2.erl
%%% Author  : alfonso <alfonso@alfonso-laptop>
%%% Description : 
%%%
%%% Created :  {% now "jS F Y H:i" %}
%%%-------------------------------------------------------------------

%%% @author This is an automated generated file
%%% @doc 
%%% This is a file representing the table {{table}}
%%% Created on {% now "jS F Y H:i" %}
%%% @end

%-module({{module}}).

-module({{module}}, [
   {% for i in columns %}
      Self_{{i.name}},
   {% endfor %} 

   {% for i in fks %}
      Self_{{i.type}}By{{i.name|capfirst}},
   {% endfor %}

   {% for i in inverse_fks %}
      Self_{{i.type}}By{{i.foreign_key_column|capfirst}},
   {% endfor %}

      Self_to_delete_flag,
      Self_old_values,
      Self_session,
      Self_hash
]).

-include("{{project}}.hrl").

-define(DAO,{{module}}_dao).

%% API
-export([   
   {% for i in columns %}
   get{{i.name|capfirst}}/0,
   set{{i.name|capfirst}}/1,
   {% endfor %}   

   {% for i in fks %}
   get{{i.type|capfirst}}By{{i.name|capfirst}}/0,
   set{{i.type|capfirst}}By{{i.name|capfirst}}/1,
   {% endfor %}
						 
{% for i in inverse_fks %}
   getListOf{{i.type|capfirst}}By{{i.foreign_key_column|capfirst}}/0,
   setListOf{{i.type|capfirst}}By{{i.foreign_key_column|capfirst}}/1,
{% endfor %}

   id/0,
   get_data/0,
   compare/1,
   modified/0,
   set_session/1,
   update/0,
   insert/0,insert/1,
   delete/0,								     
   mark_to_delete/0,
   commit/0,
   insertAndRetrieve/0,insertAndRetrieve/1,
   get_dao/0, get_type/0							     
  ]).

get_dao()->
    ?DAO.

get_type()->
    {{module}}.

set_session(NewRef)->
    ?DAO:set_session(NewRef, THIS).

get_data()->
    [
     {% for i in columns %}
         THIS#{{module}}.{{i.name}},
      {% endfor %}
      ""].



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% Getters and Setters


id()->
    IDs = [
     {% for i in columns %}
     {% ifequal i.pk "true" %}
             THIS#{{module}}.{{i.name}},
     {% endifequal %}
     {% endfor %}
    []],
    lists:reverse(tl(lists:reverse(IDs))).

{% for i in columns %}
%% @spec () -> {{i.type}}() 
%% @doc Retrieve the property {{i.name}} from record R
%% @end
get{{i.name|capfirst}}()->
    ?DAO:get{{i.name|capfirst}}(THIS).

%% @spec (NewValue) -> R
%% @doc Set the  property {{i.name}} 
%% @end
set{{i.name|capfirst}}(Value) ->
    ?DAO:set{{i.name|capfirst}}(Value, THIS).
{% endfor %}

{% for i in fks %}
get{{i.type|capfirst}}By{{i.name|capfirst}}() ->
    ?DAO:get{{i.type|capfirst}}By{{i.name|capfirst}}(THIS).

set{{i.type|capfirst}}By{{i.name|capfirst}}(NewValue)->
    ?DAO:set{{i.type|capfirst}}By{{i.name|capfirst}}(NewValue, THIS).
{% endfor %}


{% for i in inverse_fks %}
getListOf{{i.type|capfirst}}By{{i.foreign_key_column|capfirst}}() ->
    ?DAO:getListOf{{i.type|capfirst}}By{{i.foreign_key_column|capfirst}}(THIS).

setListOf{{i.type|capfirst}}By{{i.foreign_key_column|capfirst}}(ListValues) ->
    ?DAO:setListOf{{i.type|capfirst}}By{{i.foreign_key_column|capfirst}}(ListValues, THIS).
{% endfor %}


update()->
    ?DAO:update(THIS).

delete()->
    ?DAO:delete(THIS).

mark_to_delete()->
    ?DAO:mark_to_delete(THIS).

insert()->
    insert(hiberl_session).
insert(Pid)->
    ?DAO:insert(Pid, THIS).

insertAndRetrieve()->
    insertAndRetrieve(hiberl_session).
insertAndRetrieve(Pid)->
    ?DAO:insertAndRetrieve(Pid, THIS).

commit()->
    ?DAO:commit(THIS).
						      

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

compare(B) ->
    ?DAO:compare(B, THIS).

modified()->
    ?DAO:modified(THIS).

